import os, sys 
sys.path.append(os.path.dirname(os.path.dirname(__file__)))

from weiqi.dlgo.sgf.core import SgfGame 
from weiqi.dlgo.board import Move, GameState
from weiqi.dlgo.utils import Point, PrintBoard, PrintMove
from weiqi.utils import R
from weiqi.data.paraller_processor import GoDataProcessor
from weiqi.dlgo.httpfrontend.server import get_web_app
from weiqi.dlgo.agent import RandmomAgent

def run_server():
    agent = RandmomAgent()
    web_app = get_web_app({'random', agent})
    web_app.run()

def run_processor():
    processor = GoDataProcessor()
    featrues, labels = processor.LoadData()
    
    # generator = processor.LoadData('train', 100, True)
    # print(generator.GetNumberSamples())
    # generator = generator.Generate(batch_size=10)
    # x,y = next(generator)
    # print(x,y)

def run_sgfgame():
    sgf_content ="(;GM[1]FF[4]SZ[9];B[ee];W[ef];B[ff];W[df];B[fe];W[fc];B[ec];W[gd];B[fb])"
    sgf_game = SgfGame.FromString(sgf_content)
    game_state = GameState.NewGame(9)
    for item in sgf_game.MainSequenceIter():
        color, move_tuple = item.GetMove()
        if color is not None and move_tuple is not None:
            row, col = move_tuple
            point = Point(row+1, col+1)
            move = Move.Play(point)
            game_state = game_state.ApplyMove(move)
            PrintBoard(game_state.board)
            print(color, f'({row+1},{col+1})')

if __name__ == '__main__':
    # run_processor()
    run_server()


